package calvin.controller.console;

import org.datanucleus.util.StringUtils;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import calvin.listener.SimpleRateListener;

public class SetSimpleAlertController extends Controller {

    @Override
    public Navigation run() throws Exception {
        if(StringUtils.isEmpty(asString("cp")) || StringUtils.isEmpty(asString("side")) || StringUtils.isEmpty(asString("v"))) {
            requestScope("result", "NG parameters");
        } else {
            try {
                String cp = asString("cp");
                double v = asDouble("v");
                short side = asShort("side");
                SimpleRateListener.setAlert(cp, side, v);
                requestScope("result", "OK"); 
            } catch (Exception e) {
                requestScope("result", "NG parameters");
            }

        }
        return forward("setSimpleAlert.jsp");
    }
}
